package com.jdb.loan.provider.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.guns21.support.service.BaseQueryService;
import com.jdb.loan.api.query.AmountCondition;
import com.jdb.loan.provider.service.AmountConditionService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AmountConditionServiceImpl extends BaseQueryService implements AmountConditionService {

    private Map<String, AmountCondition> conditionHashMap;
    private List<AmountCondition> conditions;

    @PostConstruct
    private void init() {
        conditions = Lists.newArrayList();
        conditionHashMap = Maps.newHashMap();

        conditions.add(new AmountCondition("all", "所有金额", null, null));
        conditions.add(new AmountCondition("1000", "1000元以下", 1000, null));
        conditions.add(new AmountCondition("1001", "1001-2000元", 1001, 2000));
        conditions.add(new AmountCondition("2001", "2001-5000元", 2001, 5000));
        conditions.add(new AmountCondition("5001", "5000-10000元", 5001, 10000));
        conditions.add(new AmountCondition("10000", "10000元以下", 10000, null));
        conditions.add(new AmountCondition("10001", "10000元以上", null, 10000));

        conditionHashMap = conditions.stream().collect(Collectors.toMap(AmountCondition::getId,amountCondition -> amountCondition));
    }

    @Override
    public List<AmountCondition> listAmountConditions() {
        return conditions;
    }



    @Override
    public AmountCondition getAmountCondition(String id) {
        return null != conditionHashMap ? conditionHashMap.get(id) : null;
    }
}
